﻿// Entity Framework MapTileStore - http://maptilestore.codeplex.com/
// Copyright © 2012 Majid Qaraee
// Licensed under the Microsoft Public License (Ms-PL)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;

namespace MapEntity
{
    public class TilesDataContext : DbContext
    {
        public DbSet<Tile> Tiles { get; set; }
        public DbSet<Provider> Providers { get; set; }
        public DbSet<ImageTileSource> ImageTileSources { get; set; }

        public TilesDataContext()
            : base("name=TilesDataContext")
        {
            Database.SetInitializer<TilesDataContext>(new TilesDataContextInitializer());
        }

        //protected override void OnModelCreating(DbModelBuilder modelBuilder)
        //{
        //    base.OnModelCreating(modelBuilder);
        //}

        public class TilesDataContextInitializer
            //: DropCreateDatabaseAlways<TilesDataContext>
            : DropCreateDatabaseIfModelChanges<TilesDataContext>
        {
            protected override void Seed(TilesDataContext context)
            {
                context.Database.ExecuteSqlCommand(ResourceMapEntity.SqlQuery);
                base.Seed(context);
            }
        }
    }
}
